package com.briup.ch12;

import javax.annotation.processing.Filer;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;

/**
 * @Author briup-adam
 * @Date 2023/10/26 下午2:32
 * @Description
 **/

public class TcpClientDemo4 {
    public static void main(String[] args) {
        try {
            ArrayList<Student> list=new ArrayList<>();
            FileReader fr=new FileReader("/Users/adam/code/idea-workspace/bttc-code/02code/src/com/briup/ch12/student.txt");
            BufferedReader br = new BufferedReader(fr);
            String line=null;
            while ((line=br.readLine())!=null){
                String[] strings = line.split("[-]");
                Student stu = new Student(strings[0], Integer.parseInt(strings[1]), strings[2]);
                list.add(stu);
            }

            Socket socket = new Socket("127.0.0.1", 10001);
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(list);
            socket.shutdownOutput();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
